package com.itheima.redbaby.activity;


import com.itheima.redbaby.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class SendTimeActivity extends Activity implements OnClickListener {
	private RelativeLayout send_allday_rel;
	private RelativeLayout send_holiday_rel;
	private RelativeLayout send_workday_rel;
	private int type;
	private ImageView send_workday_img;
	private ImageView send_allday_img;
	private ImageView send_holiday_img;
	//1 => 周一至周五送货 2=> 双休日及公众假期送货 3=> 时间不限，工作日双休日及公众假期均可送货
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sendtime_activity);
		init();//初始化数据
	}
	private void init() {
		send_allday_rel =  (RelativeLayout)findViewById(R.id.send_allday_rel);
		send_holiday_rel = (RelativeLayout)findViewById(R.id.send_holiday_rel);
	    send_workday_rel = (RelativeLayout)findViewById(R.id.send_workday_rel);
		
	    send_allday_rel.setOnClickListener(this);
	    send_holiday_rel.setOnClickListener(this);
	    send_workday_rel.setOnClickListener(this);
	    
	  //图片信息 点击显示
	    send_workday_img = (ImageView) findViewById(R.id.send_workday_img);
	    send_holiday_img = (ImageView) findViewById(R.id.send_holiday_img);
	    send_allday_img = (ImageView) findViewById(R.id.send_allday_img);
	}
	@Override
	public void onClick(View v) {
		Intent data=new Intent();
		switch (v.getId()) {
		case R.id.send_allday_rel:
			//双休+工作日
			System.out.println("双休+工作日");
			type=2;
			showPic(send_allday_img);
			hidePic(send_holiday_img);
			hidePic(send_workday_img);
			
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
			break;
		case R.id.send_holiday_rel://假日
			System.out.println("节假日送");
			type=3;
			showPic(send_holiday_img);
			hidePic(send_allday_img);
			hidePic(send_workday_img);
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
			break;
		case R.id.send_workday_rel:
			System.out.println("工作日送");
			type=1;
			showPic(send_workday_img);
			hidePic(send_allday_img);
			hidePic(send_holiday_img);
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
			break;
		}
	}
	private void showPic(ImageView img) {
		img.setVisibility(View.VISIBLE);
	}
	//隐藏图片
	private void hidePic(ImageView img) {
		img.setVisibility(View.GONE);
	}
	
	@Override
	public void onBackPressed() {
//		super.onBackPressed();
		Intent data=new Intent();
		data.putExtra("type", type);
		setResult(Activity.RESULT_OK, data);
		finish();
	}
}
